<#import "commons.ftl" as m/>

package <@m.getBasePackage param=context flag=true/><@m.getApiPackage param=context flag=false/>;

import <@m.getBasePackage param=context flag=true/><@m.getModelPackage param=context flag=true/>${table.upperName}<@m.getModelSuffix param=context/>;
import <@m.getFrameBasePackage param=context flag=true/><@m.getFramePageParaPackage param=context flag=true/><@m.getFramePageResult param=context/>;
import <@m.getFrameBasePackage param=context flag=true/><@m.getFramePageParaPackage param=context flag=true/><@m.getFrameResp param=context />;
import <@m.getFrameBasePackage param=context flag=true/><@m.getFrameApiPackage param=context flag=true/><@m.getFrameApi param=context/>;
import <@m.getFrameBasePackage param=context flag=true/><@m.getFrameValidatePackage param=context flag=true/><@m.getFrameValidate param=context/>;
import <@m.getBasePackage param=context flag=true/><@m.getQueryPackage param=context flag=true/>${table.upperName}<@m.getQuerySuffix param=context/>;
import <@m.getBasePackage param=context flag=true/><@m.getParamPackage param=context flag=true/>${table.upperName}<@m.getParamSuffix param=context/>;
import <@m.getBasePackage param=context flag=true/><@m.getServicePackage param=context flag=true/><@m.getServicePrefix param=context/>${table.upperName}<@m.getServiceSuffix param=context/>;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <pre>
 *  ${(table.comment)!''} Api,控制业务流程.
 *  提供包括业务流程校验,业务流程控制.
 *
 *  <b>地址规则</b>
 *   列表或分页:GET /persons
 *   单人: GET /persons/1
 *   新增: POST /persons
 *   修改: PUT /persons
 *   删除: DELETE /persons/1
 *   关联
 *   用户下狗
 *   列表 GET /persons/1/dogs
 *   单狗 GET /persons/1/dogs/2
 *   增加狗 POST /persons/1/dogs
 *   修改狗 PUT /persons/1/dogs
 *   删除狗 DELETE /persons/1/dogs/2
 * </pre>
 *
 * @author ${context.conf.author!'系统生成'}
 * @email ${context.conf.email!'系统生成'}
 * @version ${context.conf.version!'1.0.0'}
 * @date ${.now?string('yyyy-MM-dd')}
 * @copyright ${context.conf.copyright!'系统生成'}
 */
@AllArgsConstructor
@Api(value="${(table.comment)!''}",tags={"${(table.comment)!''}"})
@RestController
public class ${table.upperName}<@m.getApiSuffix param=context/><@m.getFrameExtendsApi param=context/>{
    /**
     * ${(table.comment)!''}服务接口
     */
    private final <@m.getServicePrefix param=context/>${table.upperName}<@m.getServiceSuffix param=context/> ${table.lowerName}<@m.getServiceSuffix param=context/>;

    @ApiOperation("${(table.comment)!''}列表")
    @GetMapping("${table.lowerName}s")
    public <@m.getFramePageResult param=context/><List${_aaa!'<'}${table.upperName}<@m.getModelSuffix param=context/>${_aaa!'>'}> queryPage(${table.upperName}<@m.getQuerySuffix param=context/> query) {
        return new <@m.getFramePageResult param=context/><>(query, ${table.lowerName}<@m.getServiceSuffix param=context/>.queryPage(query));
    }

    @ApiOperation("${(table.comment)!''}获取")
    @GetMapping("${table.lowerName}s/{${table.lowerName}Id}")
    public Resp<${table.upperName}<@m.getModelSuffix param=context/>> queryById(@PathVariable ${table.pkType!'Long'} ${table.lowerName}Id) {
        return new Resp<>(${table.lowerName}<@m.getServiceSuffix param=context/>.queryById(${table.lowerName}Id));
    }

    @ApiOperation("${(table.comment)!''}新增")
    @PostMapping("${table.lowerName}s")
    public Resp<${table.pkType!'Long'}> save${table.upperName}(@RequestBody @Valid ${table.upperName}<@m.getParamSuffix param=context/> ${table.lowerName}<@m.getParamSuffix param=context/>) {
        ${table.upperName}<@m.getModelSuffix param=context/> ${table.lowerName}<@m.getModelSuffix param=context/> = new ${table.upperName}<@m.getModelSuffix param=context/>();
        BeanUtils.copyProperties(${table.lowerName}<@m.getParamSuffix param=context/>, ${table.lowerName}<@m.getModelSuffix param=context/>);
        return new Resp<>(${table.lowerName}<@m.getServiceSuffix param=context/>.insert${table.upperName}(${table.lowerName}<@m.getModelSuffix param=context/>));
    }

    @ApiOperation("${(table.comment)!''}更新")
    @PutMapping("${table.lowerName}s")
    public Resp<Integer> update${table.upperName}(@RequestBody @Validated(value = <@m.getFrameValidate param=context/>.class) ${table.upperName}<@m.getParamSuffix param=context/> ${table.lowerName}<@m.getParamSuffix param=context/>) {
        ${table.upperName}<@m.getModelSuffix param=context/> ${table.lowerName}<@m.getModelSuffix param=context/> = new ${table.upperName}<@m.getModelSuffix param=context/>();
        BeanUtils.copyProperties(${table.lowerName}<@m.getParamSuffix param=context/>, ${table.lowerName}<@m.getModelSuffix param=context/>);
        return new Resp<>(${table.lowerName}<@m.getServiceSuffix param=context/>.update${table.upperName}(${table.lowerName}));
    }

    @ApiOperation("${(table.comment)!''}删除")
    @DeleteMapping("${table.lowerName}s/{${table.lowerName}Id}")
    public Resp<Integer> deleteById(@PathVariable ${table.pkType!'Long'} ${table.lowerName}Id) {
        return new Resp<>(${table.lowerName}<@m.getServiceSuffix param=context/>.deleteById(${table.lowerName}Id));
    }

}
